package com.swak.persistence.mybatis.filter;

import java.util.List;

import org.apache.ibatis.plugin.Invocation;

/**
 * 执行器链的实现
 * 
 * @author lifeng
 * @date 2021年2月2日 上午9:57:55
 */
public class DefaultFilterChain implements FilterChain {

	private List<Filter> filters;
	private int index;

	public DefaultFilterChain(List<Filter> filters) {
		this.filters = filters;
	}

	@Override
	public Object filter(Invocation invocation) throws Throwable {
		if (this.index < this.filters.size()) {
			return this.filters.get(this.index++).filter(invocation, this);
		}
		return invocation.proceed();
	}
}
